package com.starview.star.compiler.transform;

import com.starview.star.compiler.canonical.ICondition;
import com.starview.star.compiler.canonical.IContentPattern;
import com.starview.star.compiler.util.Cons;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.util.PrettyPrintable;

@SuppressWarnings("serial")
public class MatchTriple<T extends PrettyPrintable> implements PrettyPrintable
{
  Cons<IContentPattern> args;
  ICondition cond;
  T body;

  MatchTriple(Cons<IContentPattern> args, ICondition cond, T body)
  {
    this.args = args;
    this.cond = cond;
    this.body = body;
  }

  MatchTriple(IContentPattern args[], ICondition cond, T body)
  {
    this.args = Cons.nil();
    for (int ix = args.length; ix > 0; ix--)
      this.args = new Cons<IContentPattern>(args[ix - 1], this.args);
    this.cond = cond;
    this.body = body;
  }

  MatchTriple(IContentPattern ptn, ICondition cond, T body)
  {
    this.args = Cons.nil();
    this.args = new Cons<IContentPattern>(ptn, this.args);
    this.cond = cond;
    this.body = body;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append("(");
    args.prettyPrint(disp);
    disp.append(", ");
    if (cond != null)
      cond.prettyPrint(disp);
    else
      disp.append("(no cond)");
    disp.append(", ");
    body.prettyPrint(disp);
    disp.append(")");
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }
}